.SUFFIXES: .o .s

AS		 = ca65
LD		 = ld65
CC1541 = ./cc1541
PU		 = pucrunch

all: instinct.d64

cc1541: cc1541.o
	g++ -o $@ $?

timing: timing.o
	g++ -o $@ $?
	
generators/effect.s: generators/Tunnel.java
	$(MAKE) -C generators run

rastercode_odd_1.s rastercode_even_1.s: timing generators/effect.s
	sh generateRastercode.sh
	
scroller_1.s scroller_2.s: scroller
	sh generateScroller.sh

main.s: rastercode_odd_1.s rastercode_even_1.s scroller_1.s scroller_2.s
	rm -f main.o

.s.o:
	$(AS) -U -o $*.o $*.s

OBJS = main.o

main.prg: Makefile link $(OBJS)
	$(LD) -C link -m $@.map -o $@ $(OBJS)

main: main.prg
	$(PU) -d -l 0x0800 -x 0x0800 $? $@

instinct.d64: cc1541 main
	$(CC1541) -S 8 -n TEST -i "2007!" -f TEST -w main $@

run: instinct.d64
	x64 -warp -VICIIdsize -truedrive instinct.d64

clean:
	rm -f *~ *.map *.o *.lbl *.d64 main *.prg rastercode.s timing rastercode_odd*.s rastercode_even*.s scroller*.s scroller cc1541
	$(MAKE) -C generators clean
	